/*
 * @Author: Tendo 
 * @Date: 2021-09-26 10:46:31 
 * @param {string} s
 * @return {string}
 */

 var reverseWords = function (s) {
    s = s.replace(/(^\s)|(\s*$)/g, '');// 删除头尾多余空格
    s = s.replace(/\s+/g, ' '); // 删除中间的空格，并加上一个
    let resArr = s.split(' '),
        l = -1,
        r = resArr.length;
    while (++l < --r) {
        [resArr[l], resArr[r]] = [resArr[r], resArr[l]];
    }
    return resArr.join(" ").trim();
}
